package ws.jdbc.concurrent.driver.sqlserver.tds

import ws.utils.ArrayUtil
import static ws.jdbc.concurrent.driver.sqlserver.tds.TDSMessage.*

/**
 * Test of the TDSMessage class auxiliary methods.
 * 
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
class TDSMessageAuxFunctionsTest extends GroovyTestCase {

  String serverName = "goldberg-wm"
  int portNumber = 1433

  void setUp() {
    println "-----------------------------------------------------------------"
  }

  void testIncModulo() {
    println "testIncModulo()"
    int modulo = 256
    assertEquals 1, incModulo(0, modulo)
    assertEquals 7, incModulo(6, modulo)
    assertEquals 100, incModulo(99, modulo)
    assertEquals 255, incModulo(254, modulo)
    assertEquals 0, incModulo(255, modulo)
  }

  void testSwapBits() {
    println "testSwapBits()"

    def parameters = [
      0x00, 0x12, 0x98, 0xF1, 0x1F
    ] as Byte[]
    def expected = [
      0x00, 0x21, 0x89, 0x1F, 0xF1
    ] as Byte[]
    
    parameters.eachWithIndex{val, i ->
      printf("exp=%x  res=%x\n", expected[i], swapBits(val))
      assertEquals expected[i], swapBits(val)
    } 
  }
}